Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

289
Vistas
Can not get url image storage firebase [ Error creating access token]

enter image description here

I tried uploading the image to firebase and now I can't get the image URL

I uploaded the image successfully and can't get the image's URL link

   const firebaseAdmin = require('firebase-admin');
const { v4: uuidv4 } = require('uuid');
// change the path of json file
const serviceAccount = require('./nodejs-be-upload-image-firebase-adminsdk-vzkga-bd1696a09f.json');

const admin = firebaseAdmin.initializeApp({
  credential: firebaseAdmin.credential.cert(serviceAccount),
});
const storageRef = admin.storage().bucket('gs://nodejs-be-upload-image.appspot.com');

async function uploadFile(path, filename) {
  // Upload the File
  const storage = await storageRef.upload(path, {
    public: true,
    destination: `/uploads/${filename}`,
    metadata: {
      firebaseStorageDownloadTokens: uuidv4(),
      cacheControl: 'public, max-age=315360000',
      contentType: 'image/jpeg',
    },
  });

 //I want to get the URL of the image here
    return storage[0];
//  return storage[0].metadata.mediaLink;
}
module.exports = { uploadFile };
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The Firebase Admin SDK wraps the Google Cloud Storage SDK, so their APIs are the same. The Cloud Storage SDK doesn't offer download URLs that are exactly like the ones provided by the mobile and web SDKs.

By setting the image or file as public (public: true) you wont be able to set a custom firebaseStorageDownloadTokens metadata.


There are some ways that you can get the public URL of an uploaded file.

Using getSignedUrl:

const admin = firebaseAdmin.initializeApp({
  credential: firebaseAdmin.credential.cert({
    // serviceAccount
  }),
});

const gs = 'gs://'
const bucketName = '<project-id>.appspot.com';
const storageRef = admin.storage().bucket(`${gs}${bucketName}`);

async function uploadFile(path, filename) {
  // Upload the File
  const destination = `uploads/${filename}`;

  const storage = await storageRef.upload(path, {
    public: true,
    destination: destination,
  })
  .then(() => {
    const file = storageRef.file(destination);
    return file.getSignedUrl({
      action: 'read',
      expires: '03-25-2023'
    }).then(signedUrls => {
      // signedUrls[0] contains the file's public URL
      console.log(signedUrls[0]);
    });
  });
}

Using the Cloud Storage link:

async function uploadFile(path, filename) {
  // Upload the File
  const destination = `uploads/${filename}`;

  const storage = await storageRef.upload(path, {
    public: true,
    destination: destination,
  })
  .then(() => {
  console.log(`https://storage.googleapis.com/${bucketName}/${destination}`);
  });
}

If you really do want to use customMetadata that has the firebaseStorageDownloadTokens then I would suggest to use the Web SDKs instead. Here's the documentation to start:

  • Get started with Cloud Storage on Web.
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda